package com.anmingle.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;

import static java.util.regex.Pattern.compile;

/**
 * @author 安明乐
 * @Title MatcherUtils
 * @Package IntelliJ IDEA
 * @date 2022/10/20 21:16
 */
public class MatcherUtils {

    /**
     * 输入正则表达式 和需要拆分的字符串  返回一个list集合
     * 传入ids字符串 返回 [17,23,15]id集合传入mybatis-plus删除集合类中
     *
     * @param matches
     * @param ids
     * @return
     */
    public static List jsonIntList(String matches, String ids) {
        List idList = new ArrayList();
        Matcher matcher = compile(matches).matcher(ids);
        while (matcher.find()) {
            idList.add(matcher.group());
        }
        return idList;
    }

    public static List jsonIntList(String ids) {

        List idList = new ArrayList();
        Matcher matcher = compile("\\d+").matcher(ids);
        while (matcher.find()) {
            idList.add(matcher.group());
        }
        return idList;
    }

    /**
     * 是否为 手机号
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        Matcher matcher = compile("^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-7]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\\d{8}$")
                .matcher(phone);
        return matcher.matches();
    }


    public static boolean match(String matches, String object) {
        Matcher matcher = compile(matches).matcher(object);
        return matcher.matches();
    }
}
